$def with(book, preload=False)

$ title = book.title
$ author_names = None
$if any(book.get_authors()):
    $ author_names = ", ".join(a.get("name", "Name missing") for a in book.get_authors())
$if not author_names:
    $ author_names = book.get('by_statement','')

$ cover_url = book.get_cover_url("M")
$ cover_lg = book.get_cover_url("L")

$ src = cover_url or '/images/icons/avatar_book.png'
$ srcset = '%s 2x' % (cover_lg or '/images/icons/avatar_book-lg.png')

$if preload:
    $add_metatag(tag="link", **{'rel': 'preload', 'as': 'image', 'href': src, 'imagesrcset': srcset})

<div class="coverMagic cover-animation">
    <div class="SRPCover bookCover" style="display: $cond(cover_url, 'block', 'none');">
        <a
            href="$cover_lg"
            aria-controls="seeImage"
            class="coverLook dialog--open"
            title="$_('Pull up a bigger book cover')"
        >

            <img
                itemprop="image"
                src="$src"
                srcset="$srcset"
                class="cover"
                alt="$_('Cover of: %(title)s by %(authors)s', title=title, authors=author_names)"
            >
        </a>
    </div>
    <div class="SRPCoverBlank" style="display: $cond(not cover_url, 'block', 'none');">
        <div class="innerBorder">
            <div class="BookTitle">$:macros.TruncateString(title, 45)
                <div class="Author">$:macros.TruncateString(author_names, 30)</div>
            </div>
        </div>
    </div>
</div>

<div class="hidden">
    <div class="coverFloat" id="seeImage">
        <div class="coverFloatHead">
            <h2>$:macros.TruncateString(title, 70)</h2>
            <a class="dialog--close">&times;<span class="shift">$_("Close")</span></a>
        </div>
        <a class="dialog--close"><img src="$cover_lg" class="cover" alt="$title $_('by') $author_names"/></a>
    </div>
</div>
